// 需求1:加JSDoc注释
// 需求2:上传开源


/**
 * cookie 存储
 * @param {String} key 
 * @param {Object} val 
 * @param {Number} time 
 */
function setCookie(key, val, time = 10) {

    if (typeof val == 'object') val = JSON.stringify(val)

    const d = new Date
    d.setTime(d.getTime() - 1000 * 60 * 60 * 8 + 1000 * time)
    document.cookie = `${key}=${val}; expires=${d}`
}


/**
 * cookie 获取
 * @param {String} key 
 * @returns 
 */
function getCookie(key) {

    // 1  安装;  分  ['键=值',...,'键=值']
    let arr = document.cookie.split('; ')
    // 2  遍历 item='键=值'
    for (let i = 0; i < arr.length; i++) {
        let item = arr[i]
        let tempArr = item.split('=')
        if (tempArr[0] == key) return tempArr[1]
    }
}


/**
 * cookie 删除
 * @param {String} key 
 */
function removeCookie(key) {

    setCookie(key, null, -1)
}